package com.zzz.bookdemo.config;

import com.zzz.bookdemo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
 * @author zzr
 * @date: 2025/09/27  22:00
 * @description:
 */


@Configuration
public class WebConfig implements WebMvcConfigurer {

   // 注入自定义的拦截对象
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义的拦截器对象
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") // 设置拦截器拦截的请求路径（ /** 表示拦截所有请求）
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/**/*.js") // 排除前端静态资源
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/**/*.png")
                .excludePathPatterns("/**/*.html");
    }
}
